<?php
error_reporting(E_ALL);
session_start();
include './c/config.php';
if (isset($_GET['openid'])){
	$openid=$_GET['openid'];
}
$open='not';
if (isset($_GET['open']) && !empty($_GET['open'])){
	$open=$_GET['open'];
}
function filterEmoji($str)
{ $str = preg_replace_callback(
			'/./u',
			function (array $match) {
				return strlen($match[0]) >= 4 ? '' : $match[0];
			},
			$str); 
			return $str;
}
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
$query=$mysqli->query("SELECT id FROM `users` where openid='".$openid."' limit 0,1 ");
if($query->num_rows>0){
}else{
	//$url='http://brand.fugumobile.cn/carrier/api/3rdPartyGetWXUserInfo.ashx?openid='.$openid;
	$url='http://hvacchat.carrier.com.cn/api/3rdPartyGetWXUserInfo.ashx?openid='.$openid;
	$userInfo=json_decode(file_get_contents($url), true);
	$name2=filterEmoji(addslashes($userInfo['nickname']));
	$userName=base64_encode($userInfo['nickname']);
	$headimg=$userInfo['headimg'];
	$sql="insert into users(openid,name,name2,headimg,createtime) values('".$openid."','".$userName."','".$name2."','".$headimg."','".date("Y-m-d H:i:s")."')  ";
	$mysqli->query($sql);
}
$_SESSION['openid']=$openid;
header('Location: index.php?open='.$open);
exit;